<?php

class CBank extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;

	public function __construct(){
		
		$this->_name=R_PRE."banks";
		
		$this->_primary="bankid";
		
		parent::__construct();
		
	}

	public function createBank($data){
		
		$bankid=$this->insert($data);
		
		return $bankid;
		
	}
	
	public function editBank($bankid,$data){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('bankid = ?', $bankid);
		
		$rows_affected=$db->update($this->_name,$data,$where);
		
		if($rows_affected!=1){
			
			return false;
			
		}else{
			
			return true;
			
		}
		
		
	}
	
	public function getDetail($bankid){
		
		$db=$this->getAdapter();
		
		$select = $db->select();

		$select->from($this->_name);
		
		$select->where('bankid = ? ',$bankid);
		
		return $db->fetchAll($select);
		
	}
	
	public function delBanks($bankidArray){
		
		$db=$this->getAdapter();
		
		$bankidString=join(',',$bankidArray);
		
		$result=$db->query("DELETE FROM $this->_name WHERE bankid IN ($bankidString)");
		
		return $result;
		
	}
	
	public function getAllBanks($uid){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->where(" uid = ? ",$uid);
		
		$select->order('add_time ASC');
		
		return $db->fetchAll($select);
		
	}
	

	
}